package com.wude.guild.fragment;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.umeng.analytics.MobclickAgent;
import com.wude.guild.ChoujiangActivity;
import com.wude.guild.EverydayTaskActivity;
import com.wude.guild.JifenStoreActivity;
import com.wude.guild.ListTrafficActivity;
import com.wude.guild.LoginActivity;
import com.wude.guild.MainActivity;
import com.wude.guild.R;
import com.wude.guild.WebActivity;
import com.wude.guild.servercore.mints.TitleBaseFragment;
import com.wude.tools.Utils;

/**
 * Created by 唐小妹 on 2017/12/11 0011.
 * <p>
 * 福利
 */

public class WelfareFragment3 extends TitleBaseFragment implements View.OnClickListener {
    private LinearLayout ll_traffic;//领流量
    private LinearLayout ll_choujiang;//抽奖活动
    private LinearLayout ll_everydayTask;//每日任务
    private ImageView iv_jifen;//积分商城
    private ImageView iv_questionnaire;//调查问卷
    private MainActivity activity;

    private ImageView ivTaskRed, ivFlowRed, ivChouRed;

    @Override
    protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.welfare_fragment_3, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        setHeaderTitle("福利");
        getTitleHeaderBar().getLeftImageView().setVisibility(View.GONE);

        ll_traffic = findView(view, R.id.ll_traffic);
        ll_choujiang = findView(view, R.id.ll_choujiang);
        ll_everydayTask = findView(view, R.id.ll_everydayTask);
        iv_jifen = findView(view, R.id.iv_jifen);
        iv_questionnaire = findView(view, R.id.iv_questionnaire);
        ivTaskRed = findView(view, R.id.ivTaskRed);
        ivFlowRed = findView(view, R.id.ivFlowRed);
        ivChouRed = findView(view, R.id.ivChouRed);

        ll_traffic.setOnClickListener(this);
        ll_choujiang.setOnClickListener(this);
        ll_everydayTask.setOnClickListener(this);
        iv_jifen.setOnClickListener(this);
        iv_questionnaire.setOnClickListener(this);
    }

    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("WelfareFragment");
    }

    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("WelfareFragment");
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        this.activity = (MainActivity) activity;
    }

    @Override
    public void onClick(View view) {
        if (Utils.getLoginUser() == null) {
            startActivity(new Intent(getActivity(), LoginActivity.class));
            return;
        }
        Intent intent = null;
        switch (view.getId()) {
            case R.id.ll_traffic://领流量
                intent = new Intent(getActivity(), ListTrafficActivity.class);
                break;
            case R.id.ll_choujiang://抽奖
                intent = new Intent(getActivity(), ChoujiangActivity.class);
                intent.putExtra("dayLootery", activity.dayLootery);
                break;
            case R.id.ll_everydayTask://每日任务
                intent = new Intent(getActivity(), EverydayTaskActivity.class);
                break;
            case R.id.iv_jifen://积分商城
                intent = new Intent(getActivity(), JifenStoreActivity.class);
                break;
            case R.id.iv_questionnaire://调查问卷
                intent = new Intent(getActivity(), WebActivity.class);
                intent.putExtra("title", "调查问卷");
                intent.putExtra("url", "http://nc.wudegame.com/app.php/Questionnaire/index.html");
                break;
        }

        if (intent != null)
            startActivity(intent);
    }
}
